/*
 * LifeQueen.java
 *
 * Created on September 18, 2008, 3:42 PM
 */

package lifequeen;

import java.awt.GridLayout;

/**
 *
 * @author  fcanache
 */
public class LifeQueen extends javax.swing.JFrame {

    /** Creates new form LifeQueen */
    public LifeQueen() {
        this.stopExecution = true;
        
        this.executeGoL = false;
        this.continueToNextGeneration = false;
        
        initComponents();
        manageLayers(1);
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        golGroupVersions = new javax.swing.ButtonGroup();
        jPanel1 = new javax.swing.JPanel();
        jLabel2 = new javax.swing.JLabel();
        showNQueens = new javax.swing.JButton();
        showGoL = new javax.swing.JButton();
        jPanel2 = new javax.swing.JPanel();
        chessBoard = new javax.swing.JPanel();
        chessBoardSize = new javax.swing.JTextField();
        startNQueens = new javax.swing.JButton();
        jLabel3 = new javax.swing.JLabel();
        quitNQueens = new javax.swing.JButton();
        jPanel4 = new javax.swing.JPanel();
        nQueensDelayTime = new javax.swing.JSlider();
        jScrollPane1 = new javax.swing.JScrollPane();
        nQueensDescriptionArea = new javax.swing.JTextArea();
        addQueensCalls = new javax.swing.JTextField();
        jLabel1 = new javax.swing.JLabel();
        checkingRow = new javax.swing.JTextField();
        checkingColumn = new javax.swing.JTextField();
        jLabel5 = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        jLabel7 = new javax.swing.JLabel();
        jLabel8 = new javax.swing.JLabel();
        jLabel9 = new javax.swing.JLabel();
        jLabel10 = new javax.swing.JLabel();
        drawNQueensBoard = new javax.swing.JButton();
        jLabel11 = new javax.swing.JLabel();
        stopNQueens = new javax.swing.JButton();
        jPanel3 = new javax.swing.JPanel();
        jLabel4 = new javax.swing.JLabel();
        quitGoL = new javax.swing.JButton();
        golVersion1 = new javax.swing.JRadioButton();
        golVersion2 = new javax.swing.JRadioButton();
        jLabel12 = new javax.swing.JLabel();
        golBoard = new javax.swing.JPanel();
        jLabel13 = new javax.swing.JLabel();
        golNBoardSize = new javax.swing.JTextField();
        drawGoLBoard = new javax.swing.JButton();
        stopGoL = new javax.swing.JButton();
        jPanel5 = new javax.swing.JPanel();
        jScrollPane2 = new javax.swing.JScrollPane();
        golDescriptionArea = new javax.swing.JTextArea();
        newBorns = new javax.swing.JTextField();
        newDeads = new javax.swing.JTextField();
        jLabel15 = new javax.swing.JLabel();
        jLabel16 = new javax.swing.JLabel();
        mayLive = new javax.swing.JTextField();
        jLabel17 = new javax.swing.JLabel();
        jLabel18 = new javax.swing.JLabel();
        mayDie = new javax.swing.JTextField();
        golNextGeneration = new javax.swing.JButton();
        golMBoardSize = new javax.swing.JTextField();
        jLabel14 = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        jLabel2.setFont(new java.awt.Font("Arial Black", 0, 14));
        jLabel2.setText("Welcome Screen");

        showNQueens.setText("NQUEENS");
        showNQueens.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                showNQueensMouseClicked(evt);
            }
        });

        showGoL.setText("GoL");
        showGoL.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                showGoLActionPerformed(evt);
            }
        });
        showGoL.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                showGoLMouseClicked(evt);
            }
        });

        org.jdesktop.layout.GroupLayout jPanel1Layout = new org.jdesktop.layout.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(jPanel1Layout.createSequentialGroup()
                .add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(jPanel1Layout.createSequentialGroup()
                        .addContainerGap()
                        .add(jLabel2))
                    .add(jPanel1Layout.createSequentialGroup()
                        .add(178, 178, 178)
                        .add(showNQueens)
                        .add(95, 95, 95)
                        .add(showGoL)))
                .addContainerGap(211, Short.MAX_VALUE))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .add(jLabel2)
                .add(87, 87, 87)
                .add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(showNQueens)
                    .add(showGoL))
                .addContainerGap(206, Short.MAX_VALUE))
        );

        chessBoard.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED));

        org.jdesktop.layout.GroupLayout chessBoardLayout = new org.jdesktop.layout.GroupLayout(chessBoard);
        chessBoard.setLayout(chessBoardLayout);
        chessBoardLayout.setHorizontalGroup(
            chessBoardLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(0, 37, Short.MAX_VALUE)
        );
        chessBoardLayout.setVerticalGroup(
            chessBoardLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(0, 33, Short.MAX_VALUE)
        );

        chessBoardSize.setText("4");
        chessBoardSize.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                chessBoardSizeActionPerformed(evt);
            }
        });

        startNQueens.setText("Start");
        startNQueens.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                startNQueensActionPerformed(evt);
            }
        });

        jLabel3.setFont(new java.awt.Font("Arial Black", 0, 14));
        jLabel3.setText("N - QUEENS");

        quitNQueens.setText("Exit");
        quitNQueens.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                quitNQueensActionPerformed(evt);
            }
        });

        nQueensDelayTime.setPaintLabels(true);
        nQueensDelayTime.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseReleased(java.awt.event.MouseEvent evt) {
                nQueensDelayTimeMouseReleased(evt);
            }
        });

        nQueensDescriptionArea.setColumns(20);
        nQueensDescriptionArea.setRows(5);
        jScrollPane1.setViewportView(nQueensDescriptionArea);

        addQueensCalls.setEditable(false);
        addQueensCalls.setText("0");

        jLabel1.setText("# of calls to addQueen function:");

        checkingRow.setEditable(false);
        checkingRow.setText("0");
        checkingRow.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                checkingRowActionPerformed(evt);
            }
        });

        checkingColumn.setEditable(false);
        checkingColumn.setText("0");

        jLabel5.setText("and column:");

        jLabel6.setText("Checking row: ");

        jLabel7.setText("Select your speed:");

        jLabel8.setText("0%");

        jLabel9.setText("50%");

        jLabel10.setText("100%");

        org.jdesktop.layout.GroupLayout jPanel4Layout = new org.jdesktop.layout.GroupLayout(jPanel4);
        jPanel4.setLayout(jPanel4Layout);
        jPanel4Layout.setHorizontalGroup(
            jPanel4Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(jPanel4Layout.createSequentialGroup()
                .addContainerGap()
                .add(jPanel4Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING)
                    .add(jLabel6)
                    .add(jLabel1))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(jPanel4Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(jPanel4Layout.createSequentialGroup()
                        .add(checkingRow, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 42, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(jLabel5)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(checkingColumn, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 42, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                    .add(addQueensCalls, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 200, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)))
            .add(jPanel4Layout.createSequentialGroup()
                .addContainerGap()
                .add(jLabel7)
                .addContainerGap(404, Short.MAX_VALUE))
            .add(jPanel4Layout.createSequentialGroup()
                .add(12, 12, 12)
                .add(jLabel8)
                .add(228, 228, 228)
                .add(jLabel9)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, 208, Short.MAX_VALUE)
                .add(jLabel10)
                .add(15, 15, 15))
            .add(jPanel4Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING, false)
                .add(org.jdesktop.layout.GroupLayout.LEADING, nQueensDelayTime, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .add(org.jdesktop.layout.GroupLayout.LEADING, jScrollPane1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 538, Short.MAX_VALUE))
        );
        jPanel4Layout.setVerticalGroup(
            jPanel4Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(jPanel4Layout.createSequentialGroup()
                .add(jScrollPane1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 129, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .add(18, 18, 18)
                .add(jPanel4Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(jLabel1)
                    .add(addQueensCalls, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 21, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .add(18, 18, 18)
                .add(jPanel4Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(checkingRow, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 21, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(jLabel6)
                    .add(jLabel5)
                    .add(checkingColumn, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 21, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, 48, Short.MAX_VALUE)
                .add(jLabel7)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(nQueensDelayTime, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 21, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(jPanel4Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(jLabel8)
                    .add(jLabel9)
                    .add(jLabel10))
                .add(9, 9, 9))
        );

        drawNQueensBoard.setText("Draw Board");
        drawNQueensBoard.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                drawNQueensBoardActionPerformed(evt);
            }
        });

        jLabel11.setText("Insert N:");

        stopNQueens.setText("Stop");
        stopNQueens.setEnabled(false);
        stopNQueens.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                stopNQueensActionPerformed(evt);
            }
        });

        org.jdesktop.layout.GroupLayout jPanel2Layout = new org.jdesktop.layout.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(jPanel2Layout.createSequentialGroup()
                .add(jPanel2Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(jPanel2Layout.createSequentialGroup()
                        .add(20, 20, 20)
                        .add(jLabel3, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 136, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                    .add(jPanel2Layout.createSequentialGroup()
                        .addContainerGap()
                        .add(chessBoard, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(jPanel2Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING, false)
                            .add(jPanel2Layout.createSequentialGroup()
                                .add(497, 497, 497)
                                .add(quitNQueens))
                            .add(org.jdesktop.layout.GroupLayout.TRAILING, jPanel2Layout.createSequentialGroup()
                                .add(jPanel2Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING)
                                    .add(org.jdesktop.layout.GroupLayout.LEADING, jPanel4, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                    .add(org.jdesktop.layout.GroupLayout.LEADING, jPanel2Layout.createSequentialGroup()
                                        .add(jLabel11)
                                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                                        .add(chessBoardSize, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 42, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                                        .add(drawNQueensBoard)
                                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                                        .add(startNQueens)
                                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, 156, Short.MAX_VALUE)
                                        .add(stopNQueens)))
                                .add(34, 34, 34)))))
                .addContainerGap(18, Short.MAX_VALUE))
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .add(jPanel2Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(jLabel3)
                    .add(quitNQueens))
                .add(18, 18, 18)
                .add(jPanel2Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(jLabel11)
                    .add(chessBoardSize, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 21, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(drawNQueensBoard)
                    .add(startNQueens)
                    .add(stopNQueens))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(jPanel2Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(chessBoard, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(jPanel4, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jLabel4.setFont(new java.awt.Font("Arial Black", 0, 14)); // NOI18N
        jLabel4.setText("GoL");

        quitGoL.setText("Exit");
        quitGoL.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                quitGoLActionPerformed(evt);
            }
        });

        golVersion1.setSelected(true);
        golVersion1.setText("GoL Version 1");
        golVersion1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                golVersion1ActionPerformed(evt);
            }
        });

        golVersion2.setText("GoL Version 2");

        jLabel12.setText("Choose a version:");
        jLabel12.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jLabel12MouseClicked(evt);
            }
        });

        golBoard.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));

        org.jdesktop.layout.GroupLayout golBoardLayout = new org.jdesktop.layout.GroupLayout(golBoard);
        golBoard.setLayout(golBoardLayout);
        golBoardLayout.setHorizontalGroup(
            golBoardLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(0, 37, Short.MAX_VALUE)
        );
        golBoardLayout.setVerticalGroup(
            golBoardLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(0, 33, Short.MAX_VALUE)
        );

        jLabel13.setText("Insert N:");

        golNBoardSize.setText("4");
        golNBoardSize.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                golNBoardSizeActionPerformed(evt);
            }
        });

        drawGoLBoard.setText("Draw Board");
        drawGoLBoard.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                drawGoLBoardActionPerformed(evt);
            }
        });

        stopGoL.setText("Stop");
        stopGoL.setEnabled(false);
        stopGoL.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                stopGoLActionPerformed(evt);
            }
        });

        golDescriptionArea.setColumns(20);
        golDescriptionArea.setRows(5);
        jScrollPane2.setViewportView(golDescriptionArea);

        newBorns.setEditable(false);
        newBorns.setText("0");
        newBorns.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                newBornsActionPerformed(evt);
            }
        });

        newDeads.setEditable(false);
        newDeads.setText("0");

        jLabel15.setText("New Deads:");

        jLabel16.setText("New Borns:");

        mayLive.setEditable(false);
        mayLive.setText("0");
        mayLive.setEnabled(false);
        mayLive.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                mayLiveActionPerformed(evt);
            }
        });

        jLabel17.setText("May Live:");

        jLabel18.setText("May Die:");

        mayDie.setEditable(false);
        mayDie.setText("0");
        mayDie.setEnabled(false);

        org.jdesktop.layout.GroupLayout jPanel5Layout = new org.jdesktop.layout.GroupLayout(jPanel5);
        jPanel5.setLayout(jPanel5Layout);
        jPanel5Layout.setHorizontalGroup(
            jPanel5Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(jScrollPane2, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 544, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
            .add(jPanel5Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING, false)
                .add(org.jdesktop.layout.GroupLayout.LEADING, jPanel5Layout.createSequentialGroup()
                    .add(32, 32, 32)
                    .add(jLabel17)
                    .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                    .add(mayLive, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 63, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .add(jLabel18)
                    .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
                    .add(mayDie, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 63, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .add(org.jdesktop.layout.GroupLayout.LEADING, jPanel5Layout.createSequentialGroup()
                    .addContainerGap()
                    .add(jLabel16)
                    .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                    .add(newBorns, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 63, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(26, 26, 26)
                    .add(jLabel15)
                    .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                    .add(newDeads, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 63, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)))
        );
        jPanel5Layout.setVerticalGroup(
            jPanel5Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(jPanel5Layout.createSequentialGroup()
                .add(jScrollPane2, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 129, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .add(26, 26, 26)
                .add(jPanel5Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(newBorns, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 21, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(jLabel16)
                    .add(newDeads, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 21, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(jLabel15))
                .add(30, 30, 30)
                .add(jPanel5Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(jLabel17)
                    .add(mayDie, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 21, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(mayLive, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 21, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(jLabel18))
                .addContainerGap(org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        golNextGeneration.setText("Next Gen.");
        golNextGeneration.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                golNextGenerationActionPerformed(evt);
            }
        });

        golMBoardSize.setText("4");

        jLabel14.setText("Insert M:");

        org.jdesktop.layout.GroupLayout jPanel3Layout = new org.jdesktop.layout.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(jPanel3Layout.createSequentialGroup()
                .addContainerGap()
                .add(jPanel3Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(jPanel3Layout.createSequentialGroup()
                        .add(jLabel12)
                        .add(18, 18, 18)
                        .add(golVersion1)
                        .add(18, 18, 18)
                        .add(golVersion2))
                    .add(jPanel3Layout.createSequentialGroup()
                        .add(golBoard, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(jPanel3Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                            .add(jPanel3Layout.createSequentialGroup()
                                .add(jLabel13)
                                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                                .add(golNBoardSize, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 42, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                                .add(jLabel14)
                                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                                .add(golMBoardSize, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 42, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                                .add(drawGoLBoard)
                                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                                .add(golNextGeneration)
                                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                                .add(stopGoL))
                            .add(org.jdesktop.layout.GroupLayout.TRAILING, jPanel5, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)))
                    .add(org.jdesktop.layout.GroupLayout.TRAILING, quitGoL)
                    .add(jLabel4, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 64, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .add(68, 68, 68))
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(jPanel3Layout.createSequentialGroup()
                .addContainerGap()
                .add(jPanel3Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(quitGoL)
                    .add(jLabel4))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(jPanel3Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(jLabel12)
                    .add(golVersion1)
                    .add(golVersion2))
                .add(18, 18, 18)
                .add(jPanel3Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(jLabel13)
                    .add(jLabel14)
                    .add(golNBoardSize, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 21, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(golMBoardSize, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 21, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(drawGoLBoard)
                    .add(golNextGeneration)
                    .add(stopGoL))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(jPanel3Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(golBoard, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(jPanel5, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(layout.createSequentialGroup()
                .addContainerGap()
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(jPanel3, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 679, Short.MAX_VALUE)
                    .add(layout.createSequentialGroup()
                        .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING, false)
                            .add(org.jdesktop.layout.GroupLayout.LEADING, jPanel2, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .add(org.jdesktop.layout.GroupLayout.LEADING, jPanel1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                        .addContainerGap(org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(org.jdesktop.layout.GroupLayout.TRAILING, layout.createSequentialGroup()
                .addContainerGap(34, Short.MAX_VALUE)
                .add(jPanel1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(jPanel2, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(jPanel3, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

private void quitNQueensActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_quitNQueensActionPerformed
    this.nQueensDescriptionArea.setText("Ending N-Queens game ...");    
    this.stopExecution = true;
    
    this.stopNQueens.setEnabled(false);
    this.addQueensCalls.setText("0");
    this.checkingRow.setText("0");
    this.checkingColumn.setText("0");
    
    this.chessBoardSize.setText("4");
    this.nQueensDelayTime.setValue(50);
    manageLayers(1);
}//GEN-LAST:event_quitNQueensActionPerformed

private void nQueensDelayTimeMouseReleased(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_nQueensDelayTimeMouseReleased
    
}//GEN-LAST:event_nQueensDelayTimeMouseReleased

private void startNQueensActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_startNQueensActionPerformed
    try {
        fillChessBoard(Integer.parseInt(this.chessBoardSize.getText()));
        startNQueens();
    } catch (NumberFormatException e) {
        this.nQueensDescriptionArea.setText("Please, enter a valid number");
    }
}//GEN-LAST:event_startNQueensActionPerformed

private void chessBoardSizeActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_chessBoardSizeActionPerformed
// TODO add your handling code here:
}//GEN-LAST:event_chessBoardSizeActionPerformed

private void showNQueensMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_showNQueensMouseClicked
    manageLayers(2);
}//GEN-LAST:event_showNQueensMouseClicked

private void quitGoLActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_quitGoLActionPerformed
    this.continueToNextGeneration = false;
    this.executeGoL = false;
    
    this.newBorns.setText("0");
    this.newDeads.setText("0");
    this.mayLive.setText("0");
    this.mayDie.setText("0");
    
    this.mayLive.setEnabled(false);
    this.mayDie.setEnabled(false);
    
    this.golNBoardSize.setText("4");
    this.golMBoardSize.setText("4");
    
    this.golVersion1.setSelected(true);
    
    this.drawGoLBoard.setEnabled(true);
    
    this.stopGoL.setEnabled(false);
    
    this.golNBoardSize.setEditable(true);
    this.golMBoardSize.setEditable(true);
    
    manageLayers(1);
}//GEN-LAST:event_quitGoLActionPerformed

private void showGoLMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_showGoLMouseClicked
    manageLayers(3);
}//GEN-LAST:event_showGoLMouseClicked

private void drawNQueensBoardActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_drawNQueensBoardActionPerformed
    try {
        fillChessBoard(Integer.parseInt(this.chessBoardSize.getText()));
    } catch (NumberFormatException e) {
        this.nQueensDescriptionArea.setText("Please, enter a valid number");
    }
}//GEN-LAST:event_drawNQueensBoardActionPerformed

private void stopNQueensActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_stopNQueensActionPerformed
    this.nQueensDescriptionArea.setText("Ending N-Queens game ...");    
    this.stopExecution = true;
    
    this.stopNQueens.setEnabled(false);
    this.addQueensCalls.setText("0");
    this.checkingRow.setText("0");
    this.checkingColumn.setText("0");
    
    this.golVersion1.setEnabled(true);
    this.golVersion2.setEnabled(true);
}//GEN-LAST:event_stopNQueensActionPerformed

private void checkingRowActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_checkingRowActionPerformed
// TODO add your handling code here:
}//GEN-LAST:event_checkingRowActionPerformed

private void golVersion1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_golVersion1ActionPerformed
// TODO add your handling code here:
}//GEN-LAST:event_golVersion1ActionPerformed

private void golNBoardSizeActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_golNBoardSizeActionPerformed
// TODO add your handling code here:
}//GEN-LAST:event_golNBoardSizeActionPerformed

private void drawGoLBoardActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_drawGoLBoardActionPerformed
    try {
        this.fillGoLBoard(Integer.parseInt(this.golNBoardSize.getText()), Integer.parseInt(this.golMBoardSize.getText()));
    } catch (NumberFormatException e) {
        this.golDescriptionArea.setText("Please, enter a valid number");
    }
}//GEN-LAST:event_drawGoLBoardActionPerformed

private void stopGoLActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_stopGoLActionPerformed
    this.golDescriptionArea.setText("Ending GoL game ..."); 
    this.continueToNextGeneration = false;
    this.executeGoL = false;
    
    this.newBorns.setText("0");
    this.newDeads.setText("0");
    this.mayLive.setText("0");
    this.mayDie.setText("0");
    
    this.mayLive.setEnabled(false);
    this.mayDie.setEnabled(false);
    
    this.drawGoLBoard.setEnabled(true);
    
    this.fillGoLBoard(Integer.parseInt(this.golNBoardSize.getText()), Integer.parseInt(this.golMBoardSize.getText()));
    
    this.golNBoardSize.setEditable(true);
    this.golMBoardSize.setEditable(true);
    
    this.stopGoL.setEnabled(false);
    
}//GEN-LAST:event_stopGoLActionPerformed

private void newBornsActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_newBornsActionPerformed
// TODO add your handling code here:
}//GEN-LAST:event_newBornsActionPerformed

private void mayLiveActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_mayLiveActionPerformed
// TODO add your handling code here:
}//GEN-LAST:event_mayLiveActionPerformed

private void jLabel12MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jLabel12MouseClicked
// TODO add your handling code here:
}//GEN-LAST:event_jLabel12MouseClicked

private void showGoLActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_showGoLActionPerformed
    this.golGroupVersions.add(this.golVersion1);
    this.golGroupVersions.add(this.golVersion2);
}//GEN-LAST:event_showGoLActionPerformed

private void golNextGenerationActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_golNextGenerationActionPerformed
    try {
        
        int n = Integer.parseInt(this.golNBoardSize.getText());
        int m = Integer.parseInt(this.golMBoardSize.getText());

        if (this.golVersion1.isSelected()) {
            this.mayLive.setEnabled(false);
            this.mayDie.setEnabled(false);
            if (!this.executeGoL) {

                if (this.golBoard.getComponentCount() != (n * m)) {
                    this.fillGoLBoard(n, m);
                }

                startGoL();

            } else {
                this.continueToNextGeneration = false;
            }
        } else {
            this.mayLive.setEnabled(true);
            this.mayDie.setEnabled(true);
            if (!this.executeGoL) {

                if (this.golBoard.getComponentCount() != (n * m)) {
                    this.fillGoLBoard(n, m);
                }

                startGoLVersion2();
            } else {
                this.continueToNextGeneration = false;
            }
        }
    
    } catch (NumberFormatException e) {
        this.golDescriptionArea.setText("Please, enter a valid number");
    }
}//GEN-LAST:event_golNextGenerationActionPerformed
    
    private void startGoL () {
        
        try {
            
            if (!(Integer.parseInt(this.golNBoardSize.getText()) > 0) || !(Integer.parseInt(this.golMBoardSize.getText()) > 0)) {
                throw new NumberFormatException();
            }
            
            this.drawGoLBoard.setEnabled(false);
            this.executeGoL = true;
            this.continueToNextGeneration = true;
            this.stopGoL.setEnabled(true);
            this.golVersion1.setEnabled(false);
            this.golVersion2.setEnabled(false);
            this.golNBoardSize.setEditable(false);
            this.golMBoardSize.setEditable(false);
            
            gameoflife.GameOfLife gol = new gameoflife.GameOfLife(this);
            gol.start();
            
        } catch (NumberFormatException e) {
            this.golDescriptionArea.setText("Please, enter a valid number");
        }
        
    }
    
    private void startGoLVersion2 () {
        
        try {
            
            if (!(Integer.parseInt(this.golNBoardSize.getText()) > 0) || !(Integer.parseInt(this.golMBoardSize.getText()) > 0)) {
                throw new NumberFormatException();
            }
            
            this.drawGoLBoard.setEnabled(false);
            this.executeGoL = true;
            this.continueToNextGeneration = true;
            this.stopGoL.setEnabled(true);
            this.golVersion1.setEnabled(false);
            this.golVersion2.setEnabled(false);
            this.golNBoardSize.setEditable(false);
            this.golMBoardSize.setEditable(false);
            
            gameoflife.GameOfLifeVersion2 golv2 = new gameoflife.GameOfLifeVersion2(this);
            golv2.start();
            
        } catch (NumberFormatException e) {
            this.golDescriptionArea.setText("Please, enter a valid number");
        }
        
    }
    
    public int[][] getGoLBoardConfiguration () {
        int golNBoardSizeTemp = Integer.parseInt(this.golNBoardSize.getText()) + 2;
        int golMBoardSizeTemp = Integer.parseInt(this.golMBoardSize.getText()) + 2;
        
        int configuration [][] = new int [golNBoardSizeTemp][golMBoardSizeTemp];
        
        int position;
        String info [];
        int status;
        String information;
        
        for (int i = 0; i < golNBoardSizeTemp; i++) {
            for (int j = 0; j < golMBoardSizeTemp; j++) {
                if (i == 0 || i == (golNBoardSizeTemp - 1) || j == 0 || j == (golMBoardSizeTemp - 1)) {                    
                    configuration [i][j] = 0;
                } else {
                    position = (i - 1) * (getGoLMBoardSize()) + (j - 1);
                    information = ((javax.swing.ImageIcon)(((javax.swing.JLabel)(this.golBoard.getComponent((position)))).getIcon())).getDescription();
                    info = information.split("-");

                    status = Integer.parseInt(info[2]);
                    
                    configuration[i][j] = status;
                }
            }
        }
        
        return configuration;
    }
    
    public void setGoLNewBorns (String newBorns) {
        this.newBorns.setText(newBorns);
    }
    
    public void setGoLNewDeads (String newDeads) {
        this.newDeads.setText(newDeads);
    }
    
    public void setGoLMayLive (String mayLive) {
        this.mayLive.setText(mayLive);
    }
    
    public void setGoLMayDie (String mayDie) {
        this.mayDie.setText(mayDie);
    }
    
    public void setGoLDescriptionArea (String description) {
        this.golDescriptionArea.setText(description);
    }
    
    public boolean getExecuteGoL () {
        return this.executeGoL;
    }
    
    public boolean getContinueToNextGeneration () {
        return this.continueToNextGeneration;
    }
    
    public void setContinueToNextGeneration (boolean continueToNextGeneration) {
        this.continueToNextGeneration = continueToNextGeneration;
    }
    
    private void jLabelTempMouseClicked (java.awt.event.MouseEvent evt, String information) {
        try {
            
            if (!(Integer.parseInt(this.golNBoardSize.getText()) > 0) || !(Integer.parseInt(this.golMBoardSize.getText()) > 0)) {
                throw new NumberFormatException();
            }
            
            if (!this.executeGoL) {
                String info [];
                info = information.split("-");

                int row = Integer.parseInt(info[0]);
                int column = Integer.parseInt(info[1]);
                int status = Integer.parseInt(info[2]);

                if (status == 0) {
                    placeAlive(row, column);
                } else {
                    removeAlive(row, column);
                }
            }
            
        } catch (NumberFormatException e) {
            this.golDescriptionArea.setText("Please, enter a valid number");
        }
    }
    
    public void placeAlive (int row, int column) {
        int position = row * (this.getGoLMBoardSize()) + column;
        
        String labelInformation = row + "-" + column + "-" + 1;
        
        ((javax.swing.JLabel)(golBoard.getComponent((position)))).setIcon(new javax.swing.ImageIcon(System.getProperty("user.dir")+"/src/images/whiteSquareAliveBorder.jpg", labelInformation));
            
        ((javax.swing.JLabel)(golBoard.getComponent((position)))).addMouseListener(new lifequeen.GoLMouseListener(labelInformation) {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jLabelTempMouseClicked(evt, this.getInformation());
            }
        });
        
    }
    
    public void removeAlive (int row, int column) {
        int position = (row * getGoLMBoardSize()) + column;
        
        String labelInformation = row + "-" + column + "-" + 0;
        
        ((javax.swing.JLabel)(golBoard.getComponent((position)))).setIcon(new javax.swing.ImageIcon(System.getProperty("user.dir")+"/src/images/whiteSquareBorder.jpg", labelInformation));
        
        ((javax.swing.JLabel)(golBoard.getComponent((position)))).addMouseListener(new lifequeen.GoLMouseListener(labelInformation) {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jLabelTempMouseClicked(evt, this.getInformation());
            }
        });
        
    }
    
    private void fillGoLBoard (int n, int m) {
        try {
            
            if (!(Integer.parseInt(this.golNBoardSize.getText()) > 0) || !(Integer.parseInt(this.golMBoardSize.getText()) > 0)) {
                throw new NumberFormatException();
            }
            
            this.golDescriptionArea.setText("Please, enter a new N and M to draw a different board and \nselect your initial configuration by clicking on the board. \nThen, press the Next Generation button ... ");
            this.golVersion1.setEnabled(true);
            this.golVersion2.setEnabled(true);
            
            this.golBoard.removeAll();

            golBoard.setLayout(new GridLayout(n,m));

            javax.swing.JLabel jLabelTemp;
            String labelInformation;
            for (int i = 0; i < n; i++) {

                for (int j = 0; j < m; j++) {

                    labelInformation = i + "-" + j + "-" + 0;

                    jLabelTemp = new javax.swing.JLabel(new javax.swing.ImageIcon(System.getProperty("user.dir")+"/src/images/whiteSquareBorder.jpg", labelInformation));

                    jLabelTemp.addMouseListener(new lifequeen.GoLMouseListener(labelInformation) {
                        public void mouseClicked(java.awt.event.MouseEvent evt) {
                            jLabelTempMouseClicked(evt, this.getInformation());
                        }
                    });

                    golBoard.add(jLabelTemp);

                }

            }    

            pack();
            
            
        } catch (NumberFormatException e) {
            this.golDescriptionArea.setText("Please, enter a valid number");
        }
                
    }

    public int getGoLNBoardSize () {
        int n = Integer.parseInt(this.golNBoardSize.getText());
        int m = Integer.parseInt(this.golMBoardSize.getText());
        
        if (this.golBoard.getComponentCount() != (n * m)) {
            this.fillGoLBoard(n, m);
        }
        
        return Integer.parseInt(this.golNBoardSize.getText());
    }
    
    public int getGoLMBoardSize () {
        int n = Integer.parseInt(this.golNBoardSize.getText());
        int m = Integer.parseInt(this.golMBoardSize.getText());
        
        if (this.golBoard.getComponentCount() != (n * m)) {
            this.fillGoLBoard(n, m);
        }
        
        return Integer.parseInt(this.golMBoardSize.getText());
    }
    
    private void manageLayers(int layerNumber) {
        
        switch (layerNumber) {
        
            case 1: this.jPanel1.setVisible(true);
                    this.jPanel2.setVisible(false);
                    this.jPanel3.setVisible(false);
                    break;
                    
            case 2: this.jPanel1.setVisible(false);
                    this.jPanel2.setVisible(true);
                    this.jPanel3.setVisible(false);
                    fillChessBoard(4);
                    break;
                    
            case 3: this.jPanel1.setVisible(false);
                    this.jPanel2.setVisible(false);
                    this.jPanel3.setVisible(true);
                    fillGoLBoard(4,4);
                    break;
            
            default: break;
        
        }
        
        pack();
    }
    
    private void startNQueens () {
        try {
            Integer.parseInt(this.chessBoardSize.getText());
            
            this.stopExecution = false;
            nqueens.NQueens nqueens = new nqueens.NQueens(this);
            nqueens.start();
            this.drawNQueensBoard.setEnabled(false);
            this.startNQueens.setEnabled(false);
            this.stopNQueens.setEnabled(true);
        
        } catch (NumberFormatException e) {
            this.nQueensDescriptionArea.setText("Please, enter a valid number");
        }
    }
    
    private void fillChessBoard (int n) {
        this.nQueensDescriptionArea.setText("Please, enter a new N to draw a different chessboard and/or \npress the start button to begin N-Queen ... ");
        this.chessBoard.removeAll();
        
        chessBoard.setLayout(new GridLayout(n,n));
        
        for (int i = 0; i < n; i++) {
            if ((i % 2) == 0) {
                for (int j = 0; j < n; j++) {
                    if ((j % 2) == 0) {
                        chessBoard.add(new javax.swing.JLabel(new javax.swing.ImageIcon(System.getProperty("user.dir")+"/src/images/blackSquare.jpg")));
                    } else {
                        chessBoard.add(new javax.swing.JLabel(new javax.swing.ImageIcon(System.getProperty("user.dir")+"/src/images/whiteSquare.jpg")));
                    }
                }
            } else {
                for (int j = 0; j < n; j++) {
                    if ((j % 2) == 0) {
                        chessBoard.add(new javax.swing.JLabel(new javax.swing.ImageIcon(System.getProperty("user.dir")+"/src/images/whiteSquare.jpg")));
                    } else {
                        chessBoard.add(new javax.swing.JLabel(new javax.swing.ImageIcon(System.getProperty("user.dir")+"/src/images/blackSquare.jpg")));
                    }
                }
            } 
        }    
        
        pack();
    }
    
    public int getChessBoardSize () {        
        return Integer.parseInt(this.chessBoardSize.getText());
    }
    
    public void setNQueensDescriptionArea (String description) {
        this.nQueensDescriptionArea.setText(description);
    }
    
    public void setAddQueensCalls (String description) {
        this.addQueensCalls.setText(description);
    }
    
    public void setCheckingRow (String description) {
        this.checkingRow.setText(description);
    }
    
    public void setCheckingColumn (String description) {
        this.checkingColumn.setText(description);
    }
    
    public void enableStartNQueens (boolean enable) {
        this.startNQueens.setEnabled(enable);
    }
    
    public void enableDrawNQueensBoard (boolean enable) {
        this.drawNQueensBoard.setEnabled(enable);
    }
    
    public int getNQueensDelayTime () {
        return 10000 - (this.nQueensDelayTime.getValue() * 100);
    }
    
    public boolean getStopExecution () {
        return this.stopExecution;
    }
    
    public void placeQueen (int row, int column) {
        int position = row * (getChessBoardSize()) + column;
        
        ((javax.swing.JLabel)(chessBoard.getComponent((position)))).setIcon(new javax.swing.ImageIcon(System.getProperty("user.dir")+"/src/images/redSquare.jpg"));
    }
    
    public void removeQueen (int row, int column) {
        int position = (row * getChessBoardSize()) + column;
        
        if (getChessBoardSize() % 2 == 0) {
            if((row % 2) == 0) {
                if ((position % 2) == 0) {
                    ((javax.swing.JLabel)(chessBoard.getComponent((position)))).setIcon(new javax.swing.ImageIcon(System.getProperty("user.dir")+"/src/images/blackSquare.jpg"));
                } else {
                    ((javax.swing.JLabel)(chessBoard.getComponent((position)))).setIcon(new javax.swing.ImageIcon(System.getProperty("user.dir")+"/src/images/whiteSquare.jpg"));
                }
            } else {
                if ((position % 2) == 0) {
                    ((javax.swing.JLabel)(chessBoard.getComponent((position)))).setIcon(new javax.swing.ImageIcon(System.getProperty("user.dir")+"/src/images/whiteSquare.jpg"));
                } else {
                    ((javax.swing.JLabel)(chessBoard.getComponent((position)))).setIcon(new javax.swing.ImageIcon(System.getProperty("user.dir")+"/src/images/blackSquare.jpg"));
                }
            }
        } else {
            if ((position % 2) == 0) {
                ((javax.swing.JLabel)(chessBoard.getComponent((position)))).setIcon(new javax.swing.ImageIcon(System.getProperty("user.dir")+"/src/images/blackSquare.jpg"));
            } else {
                ((javax.swing.JLabel)(chessBoard.getComponent((position)))).setIcon(new javax.swing.ImageIcon(System.getProperty("user.dir")+"/src/images/whiteSquare.jpg"));
            }
        }
    }
    
    /**
    * @param args the command line arguments
    */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new LifeQueen().setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JTextField addQueensCalls;
    private javax.swing.JTextField checkingColumn;
    private javax.swing.JTextField checkingRow;
    private javax.swing.JPanel chessBoard;
    private javax.swing.JTextField chessBoardSize;
    private javax.swing.JButton drawGoLBoard;
    private javax.swing.JButton drawNQueensBoard;
    private javax.swing.JPanel golBoard;
    private javax.swing.JTextArea golDescriptionArea;
    private javax.swing.ButtonGroup golGroupVersions;
    private javax.swing.JTextField golMBoardSize;
    private javax.swing.JTextField golNBoardSize;
    private javax.swing.JButton golNextGeneration;
    private javax.swing.JRadioButton golVersion1;
    private javax.swing.JRadioButton golVersion2;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JLabel jLabel13;
    private javax.swing.JLabel jLabel14;
    private javax.swing.JLabel jLabel15;
    private javax.swing.JLabel jLabel16;
    private javax.swing.JLabel jLabel17;
    private javax.swing.JLabel jLabel18;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JPanel jPanel4;
    private javax.swing.JPanel jPanel5;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JTextField mayDie;
    private javax.swing.JTextField mayLive;
    private javax.swing.JSlider nQueensDelayTime;
    private javax.swing.JTextArea nQueensDescriptionArea;
    private javax.swing.JTextField newBorns;
    private javax.swing.JTextField newDeads;
    private javax.swing.JButton quitGoL;
    private javax.swing.JButton quitNQueens;
    private javax.swing.JButton showGoL;
    private javax.swing.JButton showNQueens;
    private javax.swing.JButton startNQueens;
    private javax.swing.JButton stopGoL;
    private javax.swing.JButton stopNQueens;
    // End of variables declaration//GEN-END:variables
    
    private boolean stopExecution;
    
    private boolean executeGoL;
    private boolean continueToNextGeneration;
}
